package com.hy.mechanicalarm.ui.fragment;

import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.hy.mechanicalarm.R;

/**
 * Created by 韩银 on 2018/8/24 13:44
 * hanyinit@163.com
 */
@SuppressLint("ValidFragment")
public class WarmingDialogFragment  extends DialogFragment{
    public static boolean isStatus = false;
    TextView tvTip;
    int flag = 0;
    public interface WarmingDialogListener
    {
        void onWarmingDialog();
    }

    @SuppressLint("ValidFragment")
    public WarmingDialogFragment(int flag) {
        this.flag = flag;
        isStatus = true;
    }

    public static boolean isStatus(){
        return  isStatus;
    }
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
        getDialog().setCanceledOnTouchOutside(false);
        return super.onCreateView(inflater, container, savedInstanceState);
    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

        LayoutInflater inflater = getActivity().getLayoutInflater();
        View view = inflater.inflate(R.layout.fragment_warming_dialog, null);
        tvTip = view.findViewById(R.id.tvTip);
        if(flag==1){
            tvTip.setText("化合物指标出现问题");
        }else if(flag == 2){
            tvTip.setText("温度指标出现问题");
        }else if(flag == 3){
            tvTip.setText("化合物和温度指标出现问题");
        }
        builder.setView(view)
                .setPositiveButton("确定",
                        new DialogInterface.OnClickListener()
                        {
                            @Override
                            public void onClick(DialogInterface dialog, int id)
                            {
                                WarmingDialogListener warmingDialogListener = (WarmingDialogListener) getActivity();
                                warmingDialogListener.onWarmingDialog();
                            }
                        });
        return builder.create();
    }
    public boolean isShow(){
        return getDialog().isShowing();
    }
}
